package com.likianta.anykey;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.thinkcool.circletextimageview.CircleTextImageView;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Likianta_DoDoRa on 2017/11/27 0027.
 */

public class SaveUserInfo {
    
    private Group group = new Group();
    private List<Card> cardList = new ArrayList<>();
    private List<CardData> cardDataList = new ArrayList<>();
    
    public SaveUserInfo(List<CardData> cardDataList) {
        this.cardDataList = cardDataList;
    }
    
    public List<CardData> SaveCardData(EditText userTitle, EditText userName, EditText userPassword, EditText userNote, CircleTextImageView userHead, String groupName) {
        
        String cardTitle = userTitle.getText().toString();
        String cardName = userName.getText().toString();
        String cardPassword = userPassword.getText().toString();
        String cardNote = userNote.getText().toString();
        String cardSummary = "帐号：" + cardName + "\n密码：" + cardPassword + "\n备注：" + cardNote;
        LogUtil.d("sui SaveCardData传入的卡片标题名为：" + cardTitle + " 分组名为：" + groupName);
        
        group.setGroupName(groupName);
        cardList.add(new Card(cardTitle, cardSummary, userHead, 0, groupName));
        
        cardDataList.add(0, new CardData(group, cardList));
        LogUtil.d("sui 生成的cardDataList的第一个卡片的分组名为：" + cardDataList.get(0).getGroup().getGroupName());
        LogUtil.d("sui your cardDataList size is: "+cardDataList.size());
        
        return cardDataList;
    }
    
    //检测保存时的标题栏的文字是否为空，空的话禁止保存并提醒填写
    public boolean isTitleEmpty(EditText userTitle) {
        if (userTitle.getText().toString().equals("")) {
            userTitle.setHint("请输入标题");
            userTitle.setFocusable(true);
            userTitle.setFocusableInTouchMode(true);
            userTitle.requestFocus();
            
            //通过调用输入管理器来弹出软键盘
            InputMethodManager inputMethodManager = (InputMethodManager) userTitle.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(userTitle, 0);
            return true;
        }
        return false;
    }
    
}
